import store from '@/store'
import router from '@/router'
/**
 * @param {Array} value
 * @returns {Boolean}
 * @example see @/views/permission/directive.vue
 */
export default function checkPermission(value) {
  const curAth = store.getters && store.getters.curAth
  const buttons = store.getters && store.getters.buttons
  if (curAth === 'ROLE_ADMIN' || curAth === 'ROLE_DEV') {
    return true
  } else {
    if (value) {
      const permissionRoles = router.currentRoute.name + ':' + value
      const hasPermission = buttons.some(info => {
        return permissionRoles === info
      })
      if (hasPermission) {
        return true
      } else {
        return false
      }
    } else {
      return false
    }
  }
}
